void main(List<String> args) {
  // 准备购物车数据
  List carts = [
    {"count": 2, "price": 10.0, "selected": true},
    {"count": 1, "price": 30.0, "selected": false},
    {"count": 5, "price": 20.0, "selected": true}
  ];

  // 记录总金额
  double totalAmount = 0.0;
  carts.forEach((item) {
    if (item["selected"]) {
      totalAmount += item["count"] * item["price"];
    }
  });
  print(totalAmount);

  double total = carts.reduce((pre, item) {
    if (pre is double) {
      return pre + item["count"] * item["price"];
    } else {
      return pre["count"] * pre["price"] + item["count"] * item["price"];
    }
  });
  print(total);
}
